Results 1 to 3 of 3

Thread: ok, probably a silly question but.... variable scope?

  1. #1
    Developer Todesengel's Avatar
    Join Date
    Dec 2013
    Location
    St. Louis, Missouri, USA
    Posts
    266

    Default ok, probably a silly question but.... variable scope?

    So, question about scope of variables in mohaa I guess...

    I've been playing around with some of the old soundfix stuff (mapswitch.scr and friends for SP2MP type maps). I've heard there are other ways of doing this, but I'm trying to understand what is currently there, not just fix it. That setup appears to use variables for level.{weapon} to determine if the sound file should be called or not. So for example if level.rifle is not set, just return. If it is, then thread the appropriate sound requested (reload, shoot, ping, etc.). I know I can just set the variables in the individual map files as 'what needs to be fixed' isn't likely to ever change per map. But again, trying to understand what I already see there. mapswitch is being called from DMprecache.scr

    I have purples weapon mod also (love it, by the way). It uses level.{weapon} (as well as local.{weapon}) for stuff as well, but it is using them for a very different thing. It so happens that some, but not all, of these level.{weapon} variables have the same name between purples weapon mod and the soundfix flags.

    So, are these two going to step on eachother with regards to... say... level.rifle for example. Or is the engine going to say 'nah, two different threads, so different variable space'?

    Todesengel

  2. #2
    Purple Developer Purple Elephant1au's Avatar
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    1,259

    Default

    Hi,

    Predefined objects

    These object exist at all times and can be very helpful in your scripting. Look in the file Attach:g_allclasses.html in the docs folder of your MOHRadiant installation for a complete definition of these objects:
    game
    From the SDK documentation:

    Refers to the unique game object which maintains its state across levels. Only primitive values (integers/floats/strings/vectors) will persist across levels


    This is an object of class Game.
    level
    From the SDK documentation:

    Refers to the unique level object which maintains its state for the duration of a level.

    This is an object of class Level. It is commonly used to store information that is accessed by multiple threads; an alternate location to store such information would be as variables in any entities used by the threads.
    local
    From the SDK documentation:

    Refers to the thread executing the current command.

    This is an object of class ScriptThread?. It is commonly used to store variables for use by the thread. Any call to a command that does not explicitly specify an entity that it applies to will apply to local, i.e. $foo remove will apply the remove command to $foo; end will apply the end command to local.
    That was taken from http://gronnevik.se/rjukan/index.php...ScriptLanguage

    Basically there are 3 main scopes for variables.

    i. game variables which act as a global variable which *should* maintain state across all levels. Which i think is each map, levels meaning each round. Haven't tested this one.
    ii. level variables which maintain state across a level, so each round(in obj). This can be accessed from any script running on the server, so YES they will interfere with each other in your situation. To fix it, just rename all instances of the variable within one of the mods.
    iii. local variables are only maintained within the local scope of the thread. So many different threads can use the same variable name and not interfere with one another.

    Hope that helps with your experiments :P

    Purple's Playground
    OBJ :
    103.29.85.127:12203
    xfire: purpleelephant1au
    email: purpleelephant1au@gmail.com
    skydrive: PurpleElephantSkydrive




  3. #3
    Developer Todesengel's Avatar
    Join Date
    Dec 2013
    Location
    St. Louis, Missouri, USA
    Posts
    266

    Default

    That's perfect purple, I had forgotten about that site. I sure hope it never goes away, some great info there. I'm probably going to ask some questions about the soundfix that is most commonly out there. I've gotten it to work - tested and verified - but some things about the way it was originally written seem odd. New thread any moment lol

    Thanks!!

    T

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •